package top.rainf.service.impl;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.rainf.domain.vo.Friend;
import top.rainf.mapper.FriendMapper;
import top.rainf.service.IFriendService;

import java.util.List;

/**
 * @author 星环
 * @date Wed May 10 21:04:41 CST 2023
 * @description Friend服务的实现类
 */
@Service
public class FriendService implements IFriendService {

    @Autowired
    FriendMapper friendMapper;

    @Override
    public List<Friend> getFriendList() {
        return friendMapper.selectAll();
    }

    @Override
    public List<Friend> getFriendList(int uid) {
        List<Friend> friends = friendMapper.selectByUserId(uid);
        friends.forEach(friend -> friend.setUserId(uid));
        return friends;
    }

    @Override
    public Friend getOneById(int id) {
        return friendMapper.selectById(id);
    }

    @Override
    public boolean deleteOneById(int id) {
        return friendMapper.deleteById(id) == 1;
    }

    @Override
    public boolean deleteAll(List<Integer> idList) {
        return friendMapper.deleteByIds(idList) == idList.size();
    }

    @Override
    public boolean updateById(Friend friend) {
        return friendMapper.updateById(friend) == 1;
    }
}
